local haozhu = fk.CreateSkill{
  name = "investiture__haozhu",
  tags = {Skill.Compulsory}
}

Fk:loadTranslationTable{
  ["investiture__haozhu"] = "浩筑",
  [":investiture__haozhu"] = "锁定技，"
  .. "①你的回合不包含判定阶段；"
  .. "②摸牌阶段开始时，你展示牌堆顶的三张牌，然后令崇侯虎蓄谋其中一张牌；"
  .. "③若牌堆未洗过牌，则其他角色的摸牌阶段需执行②。",

  ["#investiture__haozhu-premeditate"] = "浩筑：蓄谋其中一张牌",

  ["$investiture__haozhu1"] = "轰天炮响，汪洋大海起春雷。",
  ["$investiture__haozhu2"] = "振地锣鸣，万仞山前丢霹雳。",
  ["$investiture__haozhu3"] = "三丁抽二，独丁赴役！",
  ["$investiture__haozhu4"] = "此台功成浩瀚，要动无限钱粮！",
}

local U = require "packages/utility/utility"

haozhu:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(haozhu.name) then
      return player == target
    end
  end,
  on_refresh = function (self, event, target, player, data)
    player:broadcastSkillInvoke(haozhu.name, math.random(1,2))
    -- player.room:notifySkillInvoked(player, haozhu.name, "special")
    local t = table.filter(data.phase_table, function (p)
      return p.phase ~= Player.Judge
    end)
    data.phase_table = t
  end
})

haozhu:addEffect(fk.EventPhaseStart, {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(haozhu.name) and data.phase == Player.Draw then
      return player == target or player:getMark(haozhu.name) == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(haozhu.name, math.random(3,4))
    room:notifySkillInvoked(player, haozhu.name, "drawcard")
    local cards = room:getNCards(3)
    room:turnOverCardsFromDrawPile(target, cards, haozhu.name)
    local card = room:askToChooseCard(player, {
      target = target,
      flag = { card_data = {{haozhu.name, cards},} },
      skill_name = haozhu.name,
      prompt = "#investiture__haozhu-premeditate::" .. target.id
    })
    if player:isAlive() then U.premeditate(player, card, haozhu.name, player) end
    cards = table.filter(cards, function(c) return room:getCardArea(c) == Card.Processing end)
    room:moveCardTo(table.reverse(cards), Card.DrawPile, nil, fk.ReasonJustMove, haozhu.name, nil, true, target)
  end
})

haozhu:addEffect(fk.AfterDrawPileShuffle, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(haozhu.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, haozhu.name, 1)
  end
})

return haozhu